package com.woniuxy.qiantai.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.woniuxy.qiantai.entity.Shop;
import com.woniuxy.qiantai.mapper.ShopMapper;
import com.woniuxy.qiantai.service.ShopAllService;
import com.woniuxy.qiantai.service.ShopService;
import com.woniuxy.qiantai.vo.ShopAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author firstGroup
 * @since 2023-02-22 09:45:58
 */
@Controller
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    ShopService shopService;
    @Autowired
    ShopAllService shopAllService;

    @RequestMapping("getShopDetails")
    public String getShopDetails(Integer shopId, Model model) {
        Shop shop = shopService.selectShopInfo(shopId);
        System.out.println(shop);
        model.addAttribute("shop",shop);
        return "businessDetails";
    }
//    @RequestMapping("getAll")
//    @ResponseBody
//    public Page<Shop> getAllShop(Integer currentPage,Integer pageSize) {
//
//        return shopService.getAllShop(currentPage,pageSize);
//    }
    @RequestMapping("getShopAll")
    @ResponseBody
    public PageInfo<ShopAll> getShopAll(Integer currentPage,Integer pageSize) {

        return shopAllService.shoppAll(currentPage,pageSize);
    }
    @RequestMapping("toSearchShopByES")
    public String toSearchShopByES(String keyword,Model model) {

        model.addAttribute("keyword",keyword);

        return "searchResult";
    }
//    @RequestMapping("searchShopByES")
//    @ResponseBody
//    public PageInfo<Shop> searchShopByES(String keyword, Integer currentPage, Integer pageSize) {
//        if (currentPage == null || currentPage <= 0) currentPage = 1;
//        if (pageSize == null || pageSize <= 0) pageSize = 3;
//
//        return shopService.searchShopByES(currentPage,pageSize,keyword);
//    }
    @RequestMapping("searchShopAllByES")
    @ResponseBody
    public PageInfo<ShopAll> searchShopAllByES(String keyword, Integer currentPage,
                                             Integer pageSize) {
        if (currentPage == null || currentPage <= 0) currentPage = 1;
        if (pageSize == null || pageSize <= 0) pageSize = 3;

        return shopAllService.searchShopAllByES(currentPage,pageSize,keyword);
    }
}

